## Sourobh Ghosh, Casey Kearney, Mahdi Hashemian
## Gov 2001 Replication Project

rm(list = ls())

require(readstata13)
require(sandwich)


setwd("/Users/mhashemi/Dropbox (MIT)/Gov 2001 Replication Paper/Data")  ## modify this as necessary

data = read.dta13("SovietCollaboration_MainDataset.dta")

dropsov = data[-which(data$sovietauthor == 1), ] ## dropping soviets

newt3b3 <- dropsov

##creating dummy for topsoviet
topsovietdummy = rep(0,nrow(newt3b3))
for (i in 1:nrow(newt3b3)){topsovietdummy[i] <- newt3b3$newbdrankingposition[i] }

t3b3 = cbind(newt3b3,topsovietdummy) ## put in one data frame


m5<-glm(logauthourcount ~ newbdrankingposition:afterdummy
            +  factor(adjustedmsc) + factor(year), family="poisson", data=t3b3)
#summary(m5)

##Poisson for top 10

topsovietdummy = rep(0,nrow(newt3b3))
for (i in 1:nrow(newt3b3)){  if (newt3b3$newbdrankingposition[i] < 11){topsovietdummy[i] = 1} }

t3b3 = cbind(newt3b3,topsovietdummy) ## put in one data frame

m4<-glm(logauthourcount ~ topsovietdummy:afterdummy
                 +  factor(adjustedmsc) + factor(year), family="poisson", data=t3b3)
#summary(m4)


##Poisson for top 5

topsovietdummy = rep(0,nrow(newt3b3))
for (i in 1:nrow(newt3b3)){  if (newt3b3$newbdrankingposition[i] < 6){topsovietdummy[i] = 1} }

t3b3 = cbind(newt3b3,topsovietdummy) ## put in one data frame

m3<-glm(logauthourcount ~ topsovietdummy:afterdummy
                +  factor(adjustedmsc) + factor(year), family="poisson", data=t3b3)
#summary(m3)

##Poisson for top 3
topsovietdummy = rep(0,nrow(newt3b3))
for (i in 1:nrow(newt3b3)){  if (newt3b3$newbdrankingposition[i] < 4){topsovietdummy[i] = 1} }

t3b3 = cbind(newt3b3,topsovietdummy) ## put in one data frame

m2<-glm(logauthourcount ~ topsovietdummy:afterdummy
                +  factor(adjustedmsc) + factor(year), family="poisson", data=t3b3)
#summary(m2)

##Poisson for the top 3 and top bottom

## Drop data beyond the top 3 bottom three
newt3b3 = subset(dropsov, newbdrankingposition<=3 | newbdrankingposition>=31, 
                 select=c(logauthourcount, newbdrankingposition, afterdummy, adjustedmsc, year))

topsovietdummy = rep(0,nrow(newt3b3))
for (i in 1:nrow(newt3b3)){  if (newt3b3$newbdrankingposition[i] < 4){topsovietdummy[i] = 1} }

t3b3 = cbind(newt3b3,topsovietdummy) ## put in one data frame

m1<-glm(logauthourcount ~ topsovietdummy:afterdummy
            +  factor(adjustedmsc) + factor(year), family="poisson", data=t3b3)
#summary(m1)

#Creating the Table
require(stargazer)
stargazer(m1,m2,m3,m4,m5)

